<?php

class Application_Model_Pep extends Sgit_Model
{  
    protected $_name = 'pep';
    protected $_primary = 'id';
    protected $_cache_activa = TRUE;

    
    public function getPeps($values)
    {
        
        //permite pasar unico parametro id del contador
        if(is_numeric($values)){
            $id=$values;unset($values);$values['id']=$id;unset($id);
        } 
        

        $select=$this->getAdapter()
            ->select()
            ->from(array($this->_name))
            ->joinLeft('costumer', "costumer.id = {$this->_name}.id_costumer", array('nombre','cif','razon_social','domicilio','codigo'));

           
        if (is_array($values['id']) || is_numeric($values['id']))
            $select->where("{$this->_name}.id IN (?)", $values['id']);



        if(is_numeric($values['id_costumer']))
            $select->where("id_costumer = ?", $values['id_costumer']);
        if(is_numeric($values['id_jp']))
            $select->where("id_jp = ?", $values['id_jp']);
        if(is_numeric($values['cc_mci']))
            $select->where("cc_mci = ?", $values['cc_mci']);
        

        $rows = $this->getAdapter()->fetchAll($select);
        

        foreach($rows as &$v )
        {
            $v['cc_mci_text']=$v['cc_mci'] ? 'SI' : 'NO';
        }

        if (is_numeric($values['id']))
            return $rows[0];
        else
            return $rows;

    }
}  


